package com.baby.mall.ware.controller;

import com.baby.common.utils.PageUtils;
import com.baby.common.utils.R;
import com.baby.mall.ware.entity.PurchaseEntity;
import com.baby.mall.ware.entity.vo.MergeVo;
import com.baby.mall.ware.entity.vo.PurchaseDoneVo;
import com.baby.mall.ware.service.PurchaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;



/**
 * 采购信息
 *
 * @author qinglongzhai
 * @email qinglongzhai@gmail.com
 * @date 2021-03-15 10:49:43
 */
@Api(tags = "采购信息")
@RestController
@RequestMapping("ware/purchase")
public class PurchaseController {
    @Autowired
    private PurchaseService purchaseService;

    /**
     *领取采购单
     * @Author QLZ
     * @Date 2021/3/18
     *  @param ids:采购单Id
     *  @return: null
     */
    @ApiOperation("领取采购单")
    @PostMapping("received")
    public R received(@RequestBody List<Long> ids){
        purchaseService.received(ids);
        return R.ok();

    }

    /**
     *完成采购单
     * @Author QLZ
     * @Date 2021/3/18
     *  @param doneVo:
     *  @return: null
     */
    @ApiOperation("完成采购单")
    @PostMapping("done")
    public R finished(@RequestBody PurchaseDoneVo doneVo){
        purchaseService.done(doneVo);
        return R.ok();

    }


    /**
     *合并整单
     * @Author QLZ
     * @Date 2021/3/18
     *
     *  @return: com.baby.common.utils.R
     */
    @ApiOperation("合并整单")
    @PostMapping("/merge")
    public R merge(@RequestBody  MergeVo mergeVo){
        purchaseService.mergePurechase(mergeVo);
        return R.ok();

    }

    /**
     * 选择未合并的采购单
     */
    @ApiOperation("选择未合并的采购单")
    @GetMapping("/unreceive/list")
    //@RequiresPermissions("ware:purchase:list")
    public R unreceive(@RequestParam Map<String, Object> params){
        PageUtils page = purchaseService.queryPageUnreceivePurchase(params);

        return R.ok().put("page", page);
    }

    /**
     * 列表
     */
    @ApiOperation("列表")
    @RequestMapping("/list")
    //@RequiresPermissions("ware:purchase:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = purchaseService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @ApiOperation("信息")
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("ware:purchase:info")
    public R info(@PathVariable("id") Long id){
		PurchaseEntity purchase = purchaseService.getById(id);

        return R.ok().put("purchase", purchase);
    }

    /**
     * 保存
     */
    @ApiOperation("保存")
    @RequestMapping("/save")
    //@RequiresPermissions("ware:purchase:save")
    public R save(@RequestBody PurchaseEntity purchase){
		purchaseService.save(purchase);

        return R.ok();
    }

    /**
     * 修改
     */
    @ApiOperation("修改")
    @RequestMapping("/update")
    //@RequiresPermissions("ware:purchase:update")
    public R update(@RequestBody PurchaseEntity purchase){
		purchaseService.updateById(purchase);

        return R.ok();
    }

    /**
     * 删除
     */
    @ApiOperation("删除")
    @RequestMapping("/delete")
    //@RequiresPermissions("ware:purchase:delete")
    public R delete(@RequestBody Long[] ids){
		purchaseService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
